package org.example.zuoye.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.zuoye.entity.Admin;
import org.example.zuoye.entity.Patient;
import org.example.zuoye.mapper.PatientMapper;
import org.example.zuoye.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author xinchen
 * @Date: 2024/08/13/ 11:45
 * @Description
 */
@Service
public class PatientServiceImpl implements PatientService {
    @Override
    public int editByMoney(Patient patient) {
            Patient pat = patientMapper.selectByPrimaryKey(Long.valueOf(patient.getPatId()));
            pat.setPrice(pat.getPrice()+patient.getPrice());
            int count =  patientMapper.updateByPrimaryKeySelective(pat);
            return count;
    }

    /**
     * 手机号获取用户
     * @param phone
     * @return
     */
    @Override
    public Patient findByPhone(String phone) {
        return patientMapper.findByPhone(phone);
    }

    @Autowired
    private PatientMapper patientMapper;
    /**
     * 搜索
     * @return
     */
    @Override
    public PageInfo search(Integer page, Integer limit, Patient patient) {
        try(Page<?> __ = PageHelper.startPage(page, limit)){
            List list = patientMapper.search(patient);
            PageInfo pageInfo = new PageInfo<>(list);
            return pageInfo;
        }
    }

    /**
     *  新增
     * @param patient
     */
    @Override
    public int add(Patient patient) {
        int count = patientMapper.insert(patient);
        return count;
    }

    /**
     * 修改
     * @param patient
     */
    @Override
    public int edit(Patient patient) throws Exception {
        int count =  patientMapper.updateByPrimaryKeySelective(patient);
        return count;
    }

    /**
     * 删除
     * @param ids
     */
    @Override
    public int remove(Integer[] ids) throws Exception {
        int count =  patientMapper.remove(ids);
        return count;
    }

    // @Override
    // public int editByMoney(Integer money, Integer id) {
    //     Patient patient = patientMapper.selectByPrimaryKey(Long.valueOf(id));
    //
    //     patient.setPrice(money + patient.getPrice());
    //     int count =  patientMapper.updateByPrimaryKeySelective(patient);
    //     return count;
    // }

    // @Override
    // public int editByMoney(Patient patient)throws Exception {
    //     Patient pat = patientMapper.selectByPrimaryKey(Long.valueOf(patient.getPatId()));
    //     pat.setPrice(pat.getPrice()+patient.getPrice());
    //     int count =  patientMapper.updateByPrimaryKeySelective(pat);
    //     return count;
    // }
}
